import { setAutoActivityListStor, setAutoLogsListStor } from "~store/controller/autoActivity"
import { store } from "~store"
import { message } from '@bytedance/mona-ui';

function getAutoActivityListStor() {
    window.postMessage({
        type: 'dly_activity_modole',
        shop_id: store.getState().jinritemaiShops.userShopId,
        dly_method: 'get'
    })
    getAutoSetLogsListStor()
}
function getAutoSetLogsListStor() {
    window.postMessage({
        type: 'dly_activity_modole',
        shop_id: store.getState().jinritemaiShops.userShopId,
        dly_method: 'get_logs'
    })
}
window.addEventListener('message', (event) => {
    const { type, data, dly_method } = event.data
    if (type === 'dly_activity_modole_out') {
        switch (dly_method) {
            case 'get':
                store.dispatch(setAutoActivityListStor(data))
                break;
            case 'message':
                // store.dispatch(setAutoActivityListStor(data))
                message.success(data)
                break;
            case 'get_logs':
                store.dispatch(setAutoLogsListStor(data))
                break;
            default:
                break;
        }
    }
})

export default getAutoActivityListStor